<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>设备编辑</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ equipment.id }}" name="id" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ equipment.Name }}" name="Name" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ equipment.Equid }}" name="Equid" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备版本</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ equipment.Version }}" name="Version" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备管理员</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ equipment.Equadmin }}" name="Equadmin" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">部门</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <ul id="selectParent" name="deptId" class="dtree" data-id="0"></ul>-->
<!--                    </div>-->
<!--                </div>-->


<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">角色</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        {% for role in roles %}-->
<!--                            <input{% if role.id in checked_roles %}-->
<!--                                checked-->
<!--                            {% endif %}-->
<!--                                value="{{ role.id }}" title="{{ role.name }}" type="checkbox"-->
<!--                                name="roleIds" lay-skin="primary">-->
<!--                        {% endfor %}-->
<!--                    </div>-->
<!--                </div>-->
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'admin/common/footer.html' %}
<script>
  layui.use(['form', 'jquery', 'dtree'], function () {
    let form = layui.form
    let $ = layui.jquery

    form.on('submit(user-update)', function (data) {
      let roleIds = ''
      $('input[type=checkbox]:checked').each(function () {
        roleIds += $(this).val() + ','
      })
      roleIds = roleIds.substr(0, roleIds.length - 1)
      data.field.roleIds = roleIds
      $.ajax({
        url: '/admin/equipment/update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'put',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('equipment-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
</body>
</html>